<?php defined("SYSPATH") or die("No direct script access.");

/**
* @author Kami Vaniea (Carnegie Mellon University)
*/

class audit_log_event_Core {
  static function item_created($photo) {
	db::build()->insert("audit_logs",
		array("item_id" => $photo->id,
            "user_id" =>  identity::active_user()->id,
            "action" => "create",
            "timestamp" => time()))
      ->execute();
  }

  static function item_viewed($item){
	db::build()->insert("audit_logs",
		array("item_id" => $item->id,
            "user_id" =>  identity::active_user()->id,
            "action" => "view",
            "timestamp" => time()))
      ->execute();
  }

  static function item_deleted($item){
	db::build()->insert("audit_logs",
		array("item_id" => $item->id,
            "user_id" =>  identity::active_user()->id,
            "action" => "delete",
            "timestamp" => time()))
      ->execute();
  }

  static function item_updated($original, $new){
	db::build()->insert("audit_logs",
		array("item_id" => $original->id,
            "user_id" =>  identity::active_user()->id,
            "action" => "update",
            "timestamp" => time(),
            "comment" => "Updated from " . $original->id . " to " . $new->id))
      ->execute();
  }


  static function item_edit_form_completed($item, $form){
	db::build()->insert("audit_logs",
		array("item_id" => $item->id,
            "user_id" =>  identity::active_user()->id,
            "action" => "update",
            "timestamp" => time(),
            "comment" => "Updated form " . $form->name))
      ->execute();
  }

  static function item_moved($item, $old_parent){
	db::build()->insert("audit_logs",
		array("item_id" => $item->id,
            "user_id" =>  identity::active_user()->id,
            "action" => "move",
            "timestamp" => time(),
			"comment" => "Moved to " . $item->parent->id . " from ". $old_parent))
      ->execute();
  }

}
